package com.test.demo;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * ${DESCRIPTION}
 *
 * @author muxiaoyu
 * @create 2017/05/15 10:12
 **/
public class CourseFactoryRefl {
    public static Course getCourse() throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
        Properties properties = new Properties();
        InputStream in = CourseFactoryRefl.class.getResourceAsStream("course.properties");
        //通过反射的方式创建对象
        // FileInputStream in = new FileInputStream("E:\\development\\code\\XfireWS\\src\\main\\resources\\course.properties");
        properties.load(in);
        Course course = (Course) Class.forName(properties.getProperty("class")).newInstance();
        in.close();
        return course;
    }

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
        Course course = CourseFactoryRefl.getCourse();

        course.printCourseName();
    }
}
